package antempire.control.game.operation.sceneoperation;

import java.util.ArrayList;

import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.entity.sprite.AnimatedSprite.IAnimationListener;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;

import antempire.control.game.GameConstants;
import antempire.control.game.operation.ModelInformationController;
import antempire.control.game.operation.fishoperation.AntController;
import antempire.control.game.operation.wateroperation.WaterSprite;

public class ScoringOperation implements GameConstants{
	public void ColDetBetweenBulletAndFish(ArrayList<AntController> movingFishList,
			ArrayList<WaterSprite> bulletList, ArrayList<AnimatedSprite> netList){
		
	}

	public int addScore(AntController antController, TiledTextureRegion scoreTextureRegion, 
			BaseGameActivity activity, int mScore) {
		
		this.createScoreSprite(antController.getX(), antController.getY(),
				ModelInformationController.getInstance().getAntInformation(antController.getAntName()).getScoreInformation().get_size_w(),
				ModelInformationController.getInstance().getAntInformation(antController.getAntName()).getScoreInformation().get_size_h(),
				scoreTextureRegion,activity);
		
		if(antController.getAntName() == Ant_Name.MONOMORIUM)
			mScore = mScore+4;
		else if(antController.getAntName() == Ant_Name.PHEIDOLE)
			mScore = mScore+10;
		else if(antController.getAntName() == Ant_Name.LOS)
			mScore = mScore+30;
		else if(antController.getAntName() == Ant_Name.DOLICHODERINAE)
			mScore = mScore+50;
		else 
			mScore = mScore+100;
		
		return mScore;
		
	}

	private void createScoreSprite(float x, float y, float pWidth, float pHeight, TiledTextureRegion scoreTextureRegion,final BaseGameActivity activity) {
		final AnimatedSprite scoreSprite = new AnimatedSprite(x, y-25, scoreTextureRegion.clone());
		scoreSprite.setSize(pWidth, pHeight);
		scoreSprite.animate(30,3,new IAnimationListener(){
			@Override
			public void onAnimationEnd(AnimatedSprite pAnimatedSprite){
				 activity.runOnUpdateThread(new Runnable() {
                     @Override
                     public void run() {
						activity.getEngine().getScene().getChild(LAYER_SCORE).detachChild(scoreSprite);
					}
				});
			}
		});
		activity.getEngine().getScene().getChild(LAYER_SCORE).attachChild(scoreSprite);
	}
}
